import { DB } from "../db";


let redis = DB.redis
let tableName = "t_srs_nodes"
async function addNode(h:string,nodeName:string,info:any) {
	redis.hset(tableName,nodeName,info,true)
}

async function getNode(h:string,nodeName:string) {
	return await redis.hget(tableName,nodeName,true)
}

async function getNodes(h:string) {
	let ret = await redis.hgetall(tableName,true)
	return ret
}

async function delNode(h:string,nodeName:string) {
	redis.hdel(tableName,nodeName)
}

async function refreshNode(h:string,nodeName:string,info:any) {
	redis.hset(tableName,nodeName,info,true)
}

async function refreshNodes(h:string,nodeNames:string[],infos:any[]) {
	this.delAll()
	for(let i = 0 ; i < nodeNames.length ; i ++) {
		redis.hset(tableName,nodeNames[i],infos[i],true)
	}
}

async function delAll(h:string) {
	redis.del(tableName)
}

export let RpcSrs = {
	getAll:getNodes,
	add:addNode,
	get:getNode,
	del:delNode,
	refreshAll:refreshNodes,
	refresh:refreshNode,
	delAll:delAll,
}